package com.acme.bankapp.domain.bank;

import com.acme.bankapp.domain.bank.BankException;
import com.acme.bankapp.domain.bank.NotEnoughFundsException;

public abstract class AbstractAccount implements Account 
{
	private double balance;
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(balance);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbstractAccount other = (AbstractAccount) obj;
		if (Double.doubleToLongBits(balance) != Double
				.doubleToLongBits(other.balance))
			return false;
		return true;
	}

	public AbstractAccount(double balance) throws IllegalArgumentException {
		if (balance >= 0) {
			this.balance = balance;
		}
		else {
			throw new IllegalArgumentException();
		}
	}	
	
	public double getBalance() {
		return balance;
	}

	public void setBalance(double balance) {
		this.balance = balance;
	}

	public long decimalValue() {
		return Math.round(balance);
	}	
	
	public abstract void deposit(double x);
	public abstract void withdraw(double x) throws NotEnoughFundsException;
	public abstract double maximumAmountToWithdraw();
}
